<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="753" height="366" border="0">
  <tr>
    <td height="34" colspan="6">GX College Networking</td>
  </tr>
  <tr>
    <td width="115" height="43"><a href="/StudentHomePage.php">Homepage</a></td>
    <td width="103"><a href="/StudentHomePageProfile.php">Profile</a></td>
    <td width="88">Albums</td>
    <td width="130">Friends</td>
    <td width="97"><a href="/StudentHomePageMessage.php">Messages</a></td>
    <td width="86"><a href="/logout.php">Logout</a></td>
    <td width="194">
    <form action="/ViewAllCandidateSearchStudent.php" method="post">
Enter Candidate's first name:  
<input type="text" name="firstname" />
<input type="submit" name="submit" value="submit" />
</form>
    </td>
  </tr>
  <tr>
    <td height="281"><table width="149" border="0">
      <tr>
        <td width="143"><a href="/WriteMessageFriendStudent.php">Write Message</a></td>
      </tr>
      <tr>
        <td><a href="/ViewMessages.php">View Manages</a></td>
      </tr>
    </table></td>
    <td colspan="5">
    <?php

session_start(); 
$to=$_POST['cuid'];
$from=$_SESSION['username'];
$msg=$_POST['messg'];
if(!$_POST['messg'])
{
$msg=" ";
}

//$username='gek1123';
//$msg='Hi, I want to connect with you!!!!!!!!!!!';
//$from='gip2103';
//$to='xw2174';
//$accepted='No';

$conn = oci_connect("gaurav", "gaurav", "xe"); 

//echo 'Username'.$msg.$from.$to;

$query = "INSERT INTO Messages (MessageID,Mesg,FromCUID,ToCUID) VALUES(msgseq.nextval,:message,:fromcuid,:tocuid)";

//echo 'Message'.$cuid.$password1.$fname.$mname.$lname.$address1.$address2.$city.$state.$country.$zipcode.$cellnumber.$sex.$deptid.$role;

$bindargs = array();
array_push($bindargs, array('MESSAGE', $msg, -1));
array_push($bindargs, array('FROMCUID', $from, -1));
array_push($bindargs, array('TOCUID', $to, -1));


$r = db_execute_statement($conn, $query, $bindargs);

header('Location: /ViewMessages.php');

function db_execute_statement($conn, $statement, $bindvars = array())
{
  $stid = oci_parse($conn, $statement);
  if (!$stid) {
    db_error($conn, __FILE__, __LINE__);
  }
    // Bind parameters
  foreach ($bindvars as $b) {
    // create local variable with caller specified bind value 
    $$b[0] = $b[1];
    $r = oci_bind_by_name($stid, ":$b[0]", $$b[0], $b[2]);
    if (!$r) {
      db_error($stid, __FILE__, __LINE__);
    }
  }

  $r = oci_execute($stid);
  if (!$r) {
    db_error($stid, __FILE__, __LINE__);
  }
  return($r);
}
?>
    </td>
  </tr>
</table>
</body>
</html>